﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;

namespace PeisongWeb.admin
{
    public partial class webSet : adminPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (hasPermission("HD", 1))
                {
                    getDetails();
                }
                else
                {
                    Library.Script.ClientMsgUrl("没有权限！", "index.aspx");
                    return;
                }
                
            }
        }
        private void getDetails()
        {
            WebSetEntity ws = logic.webset.list();

            hid_id.Value = ws.Id.ToString();
            if (ws.WebOn)
                rbn_WebOnYes.Checked = true;
            else
                rbn_WebOnNo.Checked = true;

            txt_MinAmount.Text = ws.MinAmount.ToString();
            txt_MinTax.Text = ws.MinTax.ToString();
            txt_RefreshMintue.Text = ws.RefreshMinute.ToString();
            txt_deliveryDocCreate.Text = ws.DeliveryDocCreateHHMM.ToString();

            if (ws.autoAddPrice)
                rbn_autoAddPriceYes.Checked = true;
            else
                rbn_autoAddPriceNo.Checked = true;

            txt_initScore.Text = ws.CompanyScore.ToString();
            if (ws.SendSMS)
                rbn_SendSMSYes.Checked = true;
            else
                rbn_SendSMSNo.Checked = true;
            //ext_updatePriceDt.SelectedTime = Convert.ToDateTime(DateTime.Now.ToShortDateString()+" "+ws.UpdatePriceDt).TimeOfDay;
            ext_updatePriceDt.Value = ws.UpdatePriceDt;
            txt_notchangePriceDay.Text = ws.NotchangePriceDay.ToString();
            txt_deductRatio.Text = string.Format("{0:F2}", ws.DeductRatio);
            txtPriceCheckStartTime.Value = ws.PriceCheckStartTime;
            txtPriceCheckEndTime.Value = ws.PriceCheckEndTime;
            chkEnablePriceCheck.Checked = ws.EnableCheckPrice;
        }
        protected void btn_Save_Click(object sender, EventArgs e)
        {
            WebSetEntity ws = new WebSetEntity();

            ws.Id = Convert.ToInt32(hid_id.Value);
            ws.WebOn = rbn_WebOnYes.Checked ? true : false;
            ws.MinAmount = Convert.ToInt32(txt_MinAmount.Text);
            ws.MinTax = Convert.ToInt32(txt_MinTax.Text);
            ws.RefreshMinute = Convert.ToInt16(txt_RefreshMintue.Text);
            ws.DeliveryDocCreateHHMM = txt_deliveryDocCreate.Text;
            ws.autoAddPrice = rbn_autoAddPriceYes.Checked ? true : false;
            ws.CompanyScore = Convert.ToInt32(txt_initScore.Text.Trim());
            ws.SendSMS = rbn_SendSMSYes.Checked ? true : false;


            ws.UpdatePriceDt = ext_updatePriceDt.SelectedTime.ToString();
            //ws.UpdatePriceDt = ext_updatePriceDt.Value.ToString();

            ws.NotchangePriceDay = Convert.ToInt32(txt_notchangePriceDay.Text.Trim());
            ws.DeductRatio = Convert.ToDecimal(txt_deductRatio.Text);

            //ws.PriceCheckStartTime = string.Format("{0}:{1}", txtPriceCheckStartTime.SelectedTime.Hours,txtPriceCheckStartTime.SelectedTime.Minutes);
            //ws.PriceCheckEndTime = string.Format("{0}:{1}",txtPriceCheckStartTime.SelectedTime.Hours,txtPriceCheckStartTime.SelectedTime.Minutes);
            ws.PriceCheckStartTime = txtPriceCheckStartTime.SelectedTime.ToString();
            ws.PriceCheckEndTime = txtPriceCheckEndTime.SelectedTime.ToString();
            log4net.ILog logger = log4net.LogManager.GetLogger("ApplicationFileAppender");
            logger.Info(ws.PriceCheckStartTime);
            ws.EnableCheckPrice = chkEnablePriceCheck.Checked;
            logic.webset.update(ws);
            getDetails();
            this.ScriptManager1.AddScript("Ext.Msg.alert('成功','&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;保存成功!&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'); ");
            return;
        }
    }
}
